package com.huawei.codearts.listener;

import com.huawei.codearts.service.AsyncService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class RedisQueueApplicationListener implements ApplicationRunner {

    @Autowired
    private AsyncService asyncService;

    /** 队列和延迟队列 demo */
    @Override
    public void run(ApplicationArguments args) throws Exception {
        log.info("RedisQueueApplicationListener ApplicationRunner is running..." + Thread.currentThread().getName());
        // 开启2个线程处理队列
        for (int i = 0; i< 2; i++) {
            asyncService.queueTask();
        }
        // 开启延迟队列
        asyncService.deferQueueTask();
    }
}
